//
//  VoltageCurrentUnbalanceDegreeTableViewController.swift
//  AlterationSwitch
//
//  Created by solarke_apple_mini_1 on 2018/10/25.
//  Copyright © 2018年 石家庄科林电气股份有限公司. All rights reserved.
//

import UIKit

class VoltageCurrentUnbalanceDegreeTableViewController: BaseTableViewController {
    @IBOutlet var labels:[UILabel]!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.tableFooterView = UIView(frame: .zero)
        notificationCenter.addObserver(self, selector: #selector(dealWithVoltageCurrentData(sender:)), name: VoltageCurrentNotification, object: nil)
    }

    @IBAction func queryButtonTap() {
        query()
    }
    
    @objc func dealWithVoltageCurrentData(sender: NSNotification) {
        let info = sender.userInfo as! [String: AnyObject]
        let data = info["data"] as AnyObject
        
        let time = data.object(forKey: "time") as! String
        labels[0].text = time
        let votageunbalance = data.object(forKey: "votageunbalance") as! Double
        labels[1].text = String(votageunbalance) + "%"
        let currentunbalance = data.object(forKey: "currentunbalance") as! Double
        labels[2].text = String(currentunbalance) + "%"
    }
    
    func query() {
        let termaddr:UnsafeMutablePointer<UInt8> = getTermaddr()
        let askOneData_fn179_send = ocFile().askOneData_fn179_send(termaddr, a3: a3)
        var arr = [UInt8](repeating: 0, count: 37)
        //将dst中的所有元素拷贝到arr中
        for i in 0..<37 {
            arr[i] = UInt8(askOneData_fn179_send[i])
        }
        sendMessageBytes(msg: arr)
        //showLoading(true)
    }
    
    // MARK: - Table view data source
    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 4
    }

}
